<template>
  <el-form
    ref="basicInformationForm"
    :model="basicInformationForm"
    label-width="99px"
    :hide-required-asterisk="true"
  >
    <Form
      :form="basicInformationForm"
      :ActivityAreaList="AreaList"
      :parentPlanName="Originalarray"
      :loding="loading"
      :title="titles"
    ></Form>
  </el-form>
</template>
<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import {
  getLists,
  insertData,
  deletelist,
  ModifierList,
} from "../../api/Genericmethods/GeneralQuery.js";
import Form from "./components/form.vue";
export default {
  // eslint-disable-next-line vue/no-unused-components
  components: { Form },
  props: {},
  data() {
    return {
      loading: true,
      // 表单参数
      basicInformationForm: {
        AccidentArea: "",
        AccidentPoint: "",
        AccidentRisk: "",
        AccidentScope: "",
        AccidentType: [],
        AccidentWarnDeal: "",
        AccidentWarnSign: "",
        Gradename: "",
        Notes: "",
        PlanName: "",
        PlanType: "",
        PossibleEffectScope: "",
        PossibleMatter: "",
        PossibleOccurArea: "",
        PossibleSeverity: "",
        PossibleTime: "",
        Possiblelinkage: [],
        Responselevel: "", //响应等级
      },
      AreaList: [
        {
          zoneofaction: "",
          AccidentArea: "",
          MeasureName: "",
          // 左边的选中状态
          currentDisposal: 0,
          Disposalserialnumber: [
            {
              DealStep: "",
              divContents: [
                {
                  DealExecutor: "",
                  contents: [{ value: "" }],
                },
              ],
            },
          ], // 存储处置信息的数组
        },
      ],
      Originalarray: "",
      titles: "",
    };
  },
  // 计算属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    // 获取具体步骤列表
    Listofspecificsteps() {
      this.loading = false;
      getLists("EmergPlan_SiteRspMrs_Deal")
        .then((data) => {
          this.loading = false;

          let array = [];
          this.AreaList = [];
          for (let index = 0; index < data.length; index++) {
            const element = data[index];
            if (element.PlanName === this.basicInformationForm.PlanName) {
              array.push(element);
            }
          }
          const sortedData = array.sort((a, b) => {
            return a.DealCode - b.DealCode;
          });
          sortedData.forEach((item) => {
            const AccidentArea = item.AccidentArea || item.AccidentPoint;
            const MeasureName = item.MeasureName;
            const AccidentPoint = item.AccidentPoint || "";
            const DealStep = item.DealStep || "";
            const DealExecutor = item.DealExecutor || "";
            let zoneofaction = "";

            if (item.AccidentArea) {
              zoneofaction = "区域";
            } else if (item.AccidentPoint) {
              zoneofaction = "设备";
            }
            let areaItem = this.AreaList.find(
              (area) =>
                area.AccidentArea === AccidentArea &&
                area.MeasureName === MeasureName &&
                area.AccidentPoint === AccidentPoint
            );
            if (!areaItem) {
              areaItem = {
                zoneofaction,
                AccidentArea,
                MeasureName,
                AccidentPoint,
                currentDisposal: 0,
                Disposalserialnumber: [],
              };
              this.AreaList.push(areaItem);
            }

            let disposalItem = areaItem.Disposalserialnumber.find(
              (disposal) => disposal.DealStep === DealStep
            );
            if (!disposalItem) {
              disposalItem = {
                DealStep,
                divContents: [
                  {
                    DealExecutor,
                    contents: [],
                  },
                ],
              };
              areaItem.Disposalserialnumber.push(disposalItem);
            } else {
              disposalItem.divContents.push({
                DealExecutor,
                contents: [],
              });
            }

            for (let j = 1; j <= 10; j++) {
              const dealContentKey = `DealContent${j}`;
              if (item.hasOwnProperty(dealContentKey) && item[dealContentKey]) {
                const value = item[dealContentKey];
                disposalItem.divContents[
                  disposalItem.divContents.length - 1
                ].contents.push({ value });
              }
            }
          });
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 判断是否一样
    isshows(list) {
      let filteredArray = list.filter((item) => {
        return item.PlanName === this.$route.query.row.PlanName;
      });
      for (let index = 0; index < filteredArray.length; index++) {
        const element = filteredArray[index];
        this.AreaList = element.ActivityAreaList;
      }
    },
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.basicInformationForm = { ...this.$route.query.row };
    this.Originalarray = this.$route.query.row;
    // console.log(this.$route.query.title);
    this.titles = this.$route.query.title;
    // 事故类型
    if (this.$route.query.row.AccidentType !== null || "") {
      let accidentTypesArray;
      if (this.$route.query.row.AccidentType.includes(",")) {
        // 判断是否包含逗号，即是否有多个事故类型
        accidentTypesArray = this.$route.query.row.AccidentType.split(",");
      } else {
        accidentTypesArray = [this.$route.query.row.AccidentType]; // 如果只有一个事故类型，直接将其组成数组
      }
      this.basicInformationForm.AccidentType = accidentTypesArray;
    }
    // 可能联动范围
    if (this.$route.query.row.Possiblelinkage !== null || "") {
      let accidentTypesArray;
      if (this.$route.query.row.Possiblelinkage.includes(",")) {
        // 判断是否包含逗号，即是否有多个事故类型
        accidentTypesArray = this.$route.query.row.Possiblelinkage.split(",");
      } else {
        accidentTypesArray = [this.$route.query.row.Possiblelinkage]; // 如果只有一个事故类型，直接将其组成数组
      }
      this.basicInformationForm.Possiblelinkage = accidentTypesArray;
    }
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.Listofspecificsteps();
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="scss" scoped></style>
